<?php $this->pageTitle = CHtml::encode($data->title) . ' - ' . Yii::app()->name ?>
<ul class="breadcrumb">
  <li><a href="/"><i class="fa fa-home"></i> 首页</a></li>
  <li><a href="<?= Yii::app()->createUrl('topic/list') ?>"><i class="fa fa-list"></i> 主题列表</a></li>
  <li><a href=""><i class="fa fa-file-text"></i> <?= $data->title ?></a></li>
</ul>
<div class="panel panel-default">
  <div class="panel-heading">
    <i class="fa fa-file-text"></i> 主题详情
  </div>
  <div class="panel-body">
    <?php if (!isset($_GET['page']) || $_GET['page'] == 1): ?>
      <div class="row">
        <div class="col-md-3">
          <!--      用户信息-->
          <p>姓名：<?= CHtml::encode($data->user->name) ?></p>

          <p>用户组：<?php if ($data->user->type == 1): ?>
              <span class="label label-info">学生</span>
            <?php elseif ($data->user->type == 2): ?>
              <span class="label label-info">教师</span>
            <?php
            else: ?>
              <span class="label label-info">管理员</span>
            <?php endif ?>
          </p>

          <p>注册时间：<?= date('Y-m-d', $data->user->created_at) ?></p>
        </div>
        <div class="col-md-8">
          <article>
            <h2 class="title"><?= CHtml::encode($data->title) ?></h2>
            <aside><i class="fa fa-clock-o"></i> <?= date('Y-m-d H:i:s', $data->created_at) ?> <i
                  class="fa fa-eye"></i> <?= $data->hits ?></aside>
            <?= CHtml::decode($data->content) ?>
          </article>
        </div>
        <div class="col-md-1"><span class="label label-success">楼主</span></div>
      </div>
      <hr/>
    <?php endif ?>
    <!--    回帖列表-->
    <?php foreach ($threads['list'] as $row): ?>
      <div class="row">
        <div class="col-md-3">
          <!--      用户信息-->
          <p>姓名：<?= CHtml::encode($row->user->name) ?></p>

          <p>用户组：<?php if ($row->user->type == 1): ?>
              <span class="label label-info">学生</span>
            <?php elseif ($row->user->type == 2): ?>
              <span class="label label-info">教师</span>
            <?php
            else: ?>
              <span class="label label-info">管理员</span>
            <?php endif ?>
          </p>

          <p>注册时间：<?= date('Y-m-d', $row->user->created_at) ?></p>
        </div>
        <div class="col-md-8">
          <article>
            <aside><i class="fa fa-clock-o"></i> <?= date('Y-m-d H:i:s', $row->created_at) ?> </aside>
            <?= CHtml::decode($row->content) ?>
          </article>
          <p>
            <?php /*if (!Yii::app()->user->isGuest): */ ?><!--
                <a href="javascript:void(0);" data-pid="<? /*= $row->thread_id */ ?>"
                   data-title="<? /*= CHtml::encode($row->user->name) */ ?>" data-action="reply">回复</a>
              --><?php /*endif */ ?>
          </p>
        </div>
      </div>
      <hr/>
    <?php endforeach ?>
    <?php
    $this->widget('CLinkPager', array(
        'pages' => $threads['pages'],
        'htmlOptions' => array(
            'class' => 'pagination'
        ),
        'firstPageLabel' => '首页',
        'lastPageLabel' => '末页',
        'nextPageLabel' => '下一页',
        'prevPageLabel' => '上一页',
        'footer' => '',
        'header' => '',
        'cssFile' => false
    ));
    ?>
  </div>
</div>
<!--回复表单-->
<?php if (!Yii::app()->user->isGuest): ?>
  <div id="reply-form" style="display: none">
    <form action="<?= Yii::app()->createUrl('topic/reply') ?>" method="post" class="form-horizontal">
      <input type="hidden" name="topic_id" id="topic_id" value="<?= $data->topic_id ?>">
      <input type="hidden" name="pid" id="pid">

      <div class="form-group">
        <div class="col-md-8">
          <p class="form-control-static">sadas</p>
          <textarea name="content" id="content" rows="8" class="form-control"></textarea>
        </div>
      </div>
      <div class="form-group">
        <div class="col-md-2">
          <button type="submit" class="btn btn-info btn-block">回复</button>
        </div>
      </div>
    </form>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading"><i class="fa fa-comment"></i> 回复:<?= $data->title ?></div>
    <div class="panel-body">
      <form action="<?= Yii::app()->createUrl('topic/reply') ?>" method="post" class="form-horizontal">
        <input type="hidden" name="pid" id="pid" value="0">
        <input type="hidden" name="topic_id" id="topic_id" value="<?= $data->topic_id ?>">

        <div class="form-group">
          <label for="content" class="control-label col-md-1">内容</label>

          <div class="col-md-8">
            <textarea name="content" id="content" class="form-control" rows="8" required=""></textarea>
          </div>
        </div>
        <div class="form-group">
          <div class="col-md-2 col-md-offset-1">
            <button type="submit" class="btn btn-info btn-block">回复</button>
          </div>
        </div>
      </form>
    </div>
    <div class="panel-footer">回帖没有做限制，所以请不要恶意灌水</div>
  </div>
<?php endif ?>
<script>
  initList();
</script>